package com.lkj.youmeng.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.lkj.youmeng.R;
import com.lkj.youmeng.data.HomeData;
import com.lkj.youmeng.mvp.view.MergeImageView;

import java.util.ArrayList;

public class RecommendAdapter extends RecyclerView.Adapter<RecommendAdapter.Holder> {
    private Context mContext;
    private ArrayList<HomeData> mList = new ArrayList<>();

    public RecommendAdapter(Context mContext, ArrayList<HomeData> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.recomend_item, null);
        return new Holder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        holder.textView.setText(mList.get(position).getTitle());
        holder.imageView.setImageBitmap(mList.get(position).getBitmap());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class Holder extends RecyclerView.ViewHolder{
        private MergeImageView imageView;
        private TextView textView;
        public Holder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.item_img);
            textView = itemView.findViewById(R.id.item_title);
        }
    }
}
